package com.uujava.minibox.gui;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;
import com.mxcyk.serviceLogic.autohiddenframe.AutoHiddenFrame;
import com.uujava.minibox.actionstyle.*;
import com.uujava.minibox.config.Config;
import com.uujava.tools.Str;
import javax.swing.*;

import java.awt.*;

final public class Main extends JFrame {
	private static final long serialVersionUID = 1L;
	Config conf = Config.getConfig();// 获取配置信息

	public Main() {
            ImageIcon im = null;
		try {
			// 此段代表是为了应对达成jar包后读取资源文件
			im = new ImageIcon(Object.class.getClass().getResource(
					"/images/0-52_.gif"));
			this.setIconImage(im.getImage());
			@SuppressWarnings("unused")
			BoxTray tray = new BoxTray(this, im);// 设置托盘
		} catch (Exception e) {
			print("图片错误路径为在类获取图片时出错");
		} 
		this.addMouseMotionListener(new WindowSnapper(this));// 窗体边界吸附效果
		new AutoHiddenFrame(this);// 窗体自动隐藏
	}

	/**
	 * 初始化配置
	 */
	public static void setConfig() {
		JLabel lab=new JLabel( new ImageIcon(Object.class.getClass().getResource(
		"/images/loading.gif")),JLabel.CENTER);
		
		final Main frome = new Main();
		frome.setTitle(Config.TITLE);
		frome.setSize(Config.Size);
		frome.setLocation(Config.Location);
		frome.add(lab);
                
                
		frome.setVisible(true);

                
                
                String[] ls3_path = { Config.APPLY + "常用应用", Config.APPLY + "游戏",
				Config.APPLY + "桌面" };
		String[] names3 = { "常用应用", "游戏", "桌面" };
		JPanel mainPanel = new ShowPanel(Config.APPLY, ls3_path, names3);
		frome.remove(lab);
		frome.add(mainPanel);// 添加所有控件

		

	}

	private final static void print(String str) {
		System.out.println(str);
	}

	// ======================================================================================================

	public static void main(String[] args) {

		/* 加载皮肤 */
	Style.beautyEye();
//			Style.seaGlass();
		/* 皮肤加载结束 */

		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				setConfig();
			}
		});
		UIManager.put("TabbedPane.tabAreaInsets",
				new javax.swing.plaf.InsetsUIResource(0, 0, 0, 0));
	}

}

class ShowPanel extends JPanel {
	North north;// 北部
	Center center;// 中部
	South south;// 南部

	public ShowPanel(String path, String[] paths, String[] names) {
		// TODO Auto-generated constructor stub
		super(new BorderLayout());

		Dimension size = new Dimension(0, 0);// 最小大小宽高都为0
		// ======北部
		north = new North(Config.PLUGINS + "上");
		north.setMinimumSize(size);// 设置最小大小为0
		// ======中部
		center = new Center(Config.PLUGINS + "左", paths, names);
		center.setMinimumSize(size);// 设置最小大小为0
		// ======南部
		south = new South(Str.bufferAppend(Config.PLUGINS , "下").toString(), "/images/reader.png",
				"/images/jiePing.jpg");
		south.setMinimumSize(size);// 设置最小大小为0

		size = null;
		// ============================================================
		this.add(north, BorderLayout.NORTH);// 北部
		this.add(center, BorderLayout.CENTER);// 中部
		this.add(south, BorderLayout.SOUTH);// 南部
	}
}
